#ifndef MODBUSPOLLWORKER_H
#define MODBUSPOLLWORKER_H

#include <QObject>
#include "modbus.h"

class ModbusPollWorker : public QObject
{
    Q_OBJECT
public:
    explicit ModbusPollWorker(QObject *parent = nullptr);
    ~ModbusPollWorker();

private:
    modbus_t* ctx;
signals:
    void response(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToReadWirte, QByteArray data);
    void opened(int err);
    void closed(int err);
public slots:
    void open(QString portName, int baudrate, char parity, int databits, int stopbits);
    void close(void);
    void modbusRtuMasterRead(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToRead);
    void modbusRtuMasterWrite(quint8 slaveAddress, quint8 functionCode, quint16 startAddress, quint32 numToWrite, QByteArray data);
};

#endif // MODBUSPOLLWORKER_H
